package main

import (
	"log"

	"github.com/micro/go-micro"
	"git.oschina.net/fanbuchi/xgggh/users/handler"
	"git.oschina.net/fanbuchi/xgggh/users/subscriber"

	profile "git.oschina.net/fanbuchi/xgggh/users/proto/user/profile"
	friend "git.oschina.net/fanbuchi/xgggh/users/proto/user/contact"
)

func main() {
	// New Service
	service := micro.NewService(
		micro.Name("com.xgggh.srv.users"),
		micro.Version("latest"),
	)

	// Register Handler
	profile.RegisterProfileHandler(service.Server(), new(handler.Profile))
	friend.RegisterContactsHandler(service.Server(),new(handler.Contact))
	// Register Struct as Subscriber
	service.Server().Subscribe(
		service.Server().NewSubscriber("topic.com.xgggh.srv.users", new(subscriber.Example)),
	)

	// Register Function as Subscriber
	service.Server().Subscribe(
		service.Server().NewSubscriber("topic.com.xgggh.srv.users", subscriber.Handler),
	)

	// Initialise service
	service.Init()

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
